package com.zf.zffencheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zf.zffencheng.dao.TenantPalaceRegionDao;
import com.zf.zffencheng.model.dto.PalaceRegionFilter;
import com.zf.zffencheng.model.pojo.PalaceRegion;
import com.zf.zffencheng.service.TenantPalaceRegionService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * ClassName: TenantPalaceRegionServiceImpl <br/>
 * Description:  <br/>
 * date: 2021/5/28 16:57<br/>
 *
 * @author william <br/>
 */
@Service
public class TenantPalaceRegionServiceImpl extends ServiceImpl<TenantPalaceRegionDao, PalaceRegion> implements TenantPalaceRegionService {


    /**
     * 大殿下的区域
     *
     * @param id
     * @return
     */
    @Override
    public List<PalaceRegion> selectByPalaceIdDesc(Integer id) {
        QueryWrapper<PalaceRegion> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("palaceId", id);
        queryWrapper.orderByDesc("createTime");
        return list(queryWrapper);
    }

    /**
     * 查询
     *
     * @param filter
     * @return
     */
    @Override
    public Page<PalaceRegion> queryFilter(PalaceRegionFilter filter) {
        Page<PalaceRegion> offset = new Page<>(filter.getPage(), filter.getPageSize());
        QueryWrapper<PalaceRegion> queryWrapper = new QueryWrapper<>();
        if(null != filter){
            if(StringUtils.hasLength(filter.getRegionName())){
                queryWrapper.like("RegionName", filter.getRegionName());
            }
            if(filter.getPalaceId() != null){
                queryWrapper.eq("PalaceID", filter.getPalaceId());
            }
        }
        queryWrapper.orderByDesc("CreateTime");
        Page<PalaceRegion> page = page(offset, queryWrapper);
        return page;
    }
}
